#include "log.h"
#include "tim_scheduler.h"

static void env_iwdg() { logi("env_iwdg"); }
static void env_smg_update() { logi("env_iwdg"); }
static void env_led_sys_flash() { logi("env_led_sys_flash"); }
static void user_cfg_write() { logi("user_cfg_write"); }
static void env_remote_scan() { logi("env_remote_scan"); }

/**
 * @brief 系统任务池
 *
 */
static task_blk tasks[TASK_MAX] = {
    {env_iwdg, 3000, TASK_DEFAULT_INIT},
    {env_smg_update, 1000, TASK_DEFAULT_INIT},
    {env_led_sys_flash, 1000, TASK_DEFAULT_INIT},
    {user_cfg_write, 3000, TASK_DEFAULT_INIT},
    {env_remote_scan, 2000, TASK_DEFAULT_INIT},
};

int main()
{
    // 将定义好的任务列表丢进去
    task_init(tasks);
    // 启动任务滴答定时器，心跳时间 1 ms
    HAL_TIM_Base_Start_IT(&htim2);
    while (1)
    {
        task_scheduler();
    }
}

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
    if (htim->Instance == TIM2) // 1ms 刷新一次后端业务系统
    {
        task_tick();
    }
}